# 将a,b的值交换
a = 'hello'
b = 'world'
a, b = b, a
print(a, b)


# 判断一个字符串是不是汇文


def fn(str1):
    if str1 == str1[::-1]:
        print('是回文')
    else:
        print('不是回文')


fn('abcba')

# 已知一个字符串为 "hello_world_itsource", 如何得到一个队列 ["hello","world","itsource"]
str2 = 'hello_world_itsource'
print(str2.split('_'))

# 有个列表 ["hello", "world", "itsource"]如何把把列表里面的字符串联起来，得到字符串 "hello_world_itsourceo"
print('_'.join(["hello", "world", "itsource"]))

# 把字符串 s 中的每个空格替换成"%20",输入：s = "We are happy.",输出："We%20are%20happy."
s = 'We are happy'
print(s.replace(' ', '%20'))

# 打印九九乘法表
for i in range(1, 10):
    for j in range(1, i + 1):
        print(f'{j} * {i} ={j * i}', end='  ')
    print()


# 找出单词 "welcome" 在 字符串"Hello, welcome to my world." 中出现的位置，找不到返回-1,从下标0开始索引
def find_keyword(source_data, keyword):
    if keyword in source_data:
        return source_data.find(keyword)
    else:
        return -1


print(find_keyword('Hello, welcome to my world.', 'welcome'))
source_data = 'Hello, welcome to my world.'
keyword = 'welcome'
print(source_data.find(keyword))

# 统计字符串“Hello, welcome to my world.” 中字母w出现的次数,统计单词 my 出现的次数
a = 'Hello, welcome to my world.'
print(a.count('w'))
print(a.count('my'))
